package cn.abellflower.dzfp;

/**
 * @Description
 * @Author gbzdyf@126.com
 * @Date 2020/10/19 8:53 下午
 */
public class MessageConsumerImpl implements MessageConsumer {

    private ConsumerConfig consumerConfig;

    /**
     * 请求关闭consumer
     */
    private volatile boolean closeRequested = false;

    public MessageConsumerImpl(ConsumerConfig consumerConfig) {
        this.consumerConfig = consumerConfig;
    }

    @Override
    public void start() {
        Thread thread = new Thread(new ConsumerThread());
        thread.start();
    }

    @Override
    public void close() {
        closeRequested = true;
    }


    private class ConsumerThread extends Thread {
        @Override
        public void run() {
            while (!closeRequested) {
                ConsumerCallBack consumerCallBack = consumerConfig.getConsumerCallBack();
                consumerCallBack.onMessage("我是");
            }
        }
    }
}
